package communication.impl;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import communication.NetworkService;

public class Sender {

	public void send() throws RemoteException {
		CallbackServerObject callbackServerObject = 
				new CallbackServerObject("ADMIN1");
		try {
			int clientPort = Integer.parseInt(
				System.getProperty("protocole.callback.client.port", "34002"));
			int registryPort = Integer.parseInt(
				System.getProperty("protocole.callback.registry.port", "34001"));
			String registryHost =
				System.getProperty("protocole.callback.registry.host", "127.0.0.1");
			String networkServiceBindingName =
					System.getProperty("protocole.callback.binding.name", 
							NetworkService.RTDGNetworkServiceBindingName);

			UnicastRemoteObject.exportObject(callbackServerObject, clientPort);
			
			Registry remoteRegistry = 
					LocateRegistry.getRegistry(registryHost, registryPort);
			
			NetworkService remoteService = (NetworkService)
					remoteRegistry.lookup(networkServiceBindingName);
			
			System.out.println("Pret !!!");
			remoteService.register(callbackServerObject);
			
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}

